Return to doc.sitecore.com

5.  Implementing Custom Domain Functionality
Prev

It is possible to extend the functionality which a domain is responsible for. For example, user credentials may be validated by a third party tool (CRM), some actions may be performed during login, logout or other operations which the Domain object performs.

A class which implements the functionality of this kind should inherit from the Sitecore.SecurityModel.Domain class. This class should be referenced in the type attribute of the <domain> definition.

5.1.  Example

We will create the ExtDomain object which will add a record to the Log file every time a user logs in or logs out of Sitecore.

Source Code

namespace Sitecore.Extension
{    
    
public class ExtDomain: Domain
    {
      
public ExtDomain(string domainName, string databaseName):base(domainName, databaseName){}
      
public override DomainAccessResult Login(string userName, string userPassword)
      {
         DomainAccessResult result
= base.Login (userName, userPassword);
        
if(result.Success)
         {
            Log.Info(
string.Format("{0} logged in", userName), this);
         }
        
return result;
      }
      
public override DomainAccessResult Logout()
      {
DomainAccessResult result
= base.Logout();
        
if(result.Success)
         {
            Log.Info(
string.Format("{0} logged out", base.CurrentUser.Name), this);
         }
        
return result;
      }
    }
}

Web.config Change

Replace the default Domain object with our custom one.

Change the following <domain> definition in the sitecore/domains section:

      <domain id="sitecore" singleInstance="true" type="Sitecore.SecurityModel.Domain, Sitecore.Kernel">

        <param desc="name">$(id)</param>

        <param desc="database">security</param>

        <Appearance.ShortDescription>The main Sitecore domain</Appearance.ShortDescription>

      </domain>

to:

      <domain id="sitecore" singleInstance="true" type="Sitecore.Extension.ExtDomain, ExtDomain">

        <param desc="name">$(id)</param>

        <param desc="database">security</param>

        <Appearance.ShortDescription>The main Sitecore domain</Appearance.ShortDescription>

      </domain>

where ExtDomain is the name of the ExtDomain class assembly.

Now login/logout events will be written to the log file.


Prev